<?php

class Libs_GlobalFuncBack
{

    /**
	* �������
	*/
    private static $_cache;

    const  UC_KEY='a';
    /**
	* ����һ�������б�
	* @param array $data ���飬�Լ�ֵ�Ե���ʽ����
	* @param string $id �?ID
	* @param string $name �?���
	* @param string $default Ĭ��ֵ
	* @param mixed  $key Ĭ��KEY
	* @param string $otherstr �����ַ�
	* @return htmlElement
	*/
    public static function createSelectElement($data, $id='', $name='', $default='', $key=null, $otherstr='', $selectClass='') {
        $class = $selectClass ? ' class="' . $selectClass . '"' : '';
        $sel = '';
        $sel = '<select '.(($id) ? 'id="' . $id . '"' : '').' name="' . $name . '"' . $otherstr . ' ' . $class . '>';
        $sel .= $default ? '<option value="">' . $default . '</option>' : '';
        if ($data && is_array($data)) {
            foreach ($data as $k=>$v) {
                if (is_array($v)) {
                    $k = $v['id'];
                    $v = $v['name'];
                }
                $sel .= '<option value="' . $k . '" ';
                $sel .= ($key == $k && $key !== null) ? ' selected="selected"' : '';
                $sel .= '>' . $v . '</option>' . chr(10) . chr(13);
            }
        }
        $sel .= '</select>';
        return $sel;
    }

    /**
	* ��дarray_merge_recursive����
	*/
    public static function &arrayMergeRecursive()
    {
        $arrays = func_get_args();
        $merged = $arrays[0];

        $arrayCount = count($arrays);
        for($i = 0; $i < $arrayCount; $i++) {
            if (is_array($arrays[$i])) {
                foreach ($arrays[$i] as $key => $val) {
                    if (is_array($val)) {
                        $merged[$key] = !empty($merged[$key]) && is_array($merged[$key]) ?
                        self::arrayMergeRecursive($merged[$key], $arrays[$i][$key]) :
                        $arrays[$i][$key];
                    } else {
                        $merged[$key] = $val;
                    }
                }
            }
        }
        return $merged;
    }

    public static function arrayFilter(array $input, $callback = null)
    {
        foreach ($input as &$value) {
            if (is_array($value)) {
                $value = self::arrayFilter($value, $callback);
            }
        }
        return array_filter($input);
    }

    /**
	* �ݹ�ϲ�����Ϊһά����
	*/
    public static function arrayMulti2Single(array $arr, $preserveKey = true)
    {
        static $re = array();
        foreach ($arr as $key => $val) {
            if (is_array($val)) {
                self::arrayMulti2Single($val, $preserveKey);
            } else {
                if ($preserveKey) {
                    $re[$key] = $val;
                } else {
                    $re[] = $val;
                }
            }
        }
        return $re;
    }

    /**
	* UTF8תGBK
	* 
	* @param string $str
	* @return string
	*/
    public static function utf82gbk($str)
    {
        if (is_array($str)) {
            foreach ($str as &$row) {
                $row = self::utf82gbk($row);
            }
            return $str;
        }

        if (mb_check_encoding($str, 'UTF8')) {
            return iconv('UTF8','GBK', $str);
        } else if(mb_check_encoding($str, 'GBK')) {
            return $str;
        } else {
            return false;
        }
    }


    /**
	* GBKתUTF8
	* 
	* @param string $str
	* @return string
	*/
    public static function gbk2utf8($str)
    {
        if (is_array($str)) {
            foreach ($str as &$row) {
                $row = self::gbk2utf8($row);
            }
            return $str;
        }

        if (mb_check_encoding($str, 'GBK')) {
            return iconv('GBK','UTF-8', $str);
        } else if(mb_check_encoding($str, 'UTF-8')) {
            return $str;
        } else {
            return false;
        }
    }

    /**
	 * ��ȡJS����
	 * @param <type> $code JS����
	 */
    public static function js($code)
    {
        return '<script type="text/javascript"><!--' . $code . '--></script>';
    }


    /**
	 * ����JS����
	 * @param array $varArr �������� ��ֵ��
	 */
    public static function getExtractJs(array $varArr)
    {
        $jsValArr = array();
        $jsValArr[] = '';
        foreach($varArr as $key => $val) {
            $jsValArr[] = "var {$key} = '{$val}'";
        }
        $jsValArr[] = '';

        return self::js(join("\r\n", $jsValArr));
    }
    /**
	 * ��ȡ�����ַ�...
	 *
	 * @param $str Ҫ��ȡ���ַ�
	 * @param $strlen Ӣ�ĳ���
	 */
    public static function cnSubstr($str,$strlen=10) {
        if(empty($str)||!is_numeric($strlen)){
            return false;
        }
        if(strlen($str)<=$strlen){
            return $str;
        }

        $last_word_needed=substr($str,$strlen-1,1);
        if(!ord($last_word_needed)>128){
            $needed_sub_sentence=substr($str,0,$strlen);
            return $needed_sub_sentence;
        }else{
            for($i=0;$i<$strlen;$i++){
                if(ord($str[$i])>128){
                    $i++;
                }
            }
            $needed_sub_sentence=substr($str,0,$i);
            return $needed_sub_sentence;
        }
    }
    /**
	 * �жϿͻ����Ƿ�����������
	 */
    public static function isSpider(){
        static $spider = NULL;
        if ($spider!== NULL){
            return $spider;
        }
        if (empty($_SERVER['HTTP_USER_AGENT'])){
            $spider = '';
            return '';
        }

        $searchengine_bot = array(
        'googlebot',
        'mediapartners-google',
        'baiduspider+',
        'msnbot',
        'yodaobot',
        'yahoo! slurp;',
        'yahoo! slurp china;',
        'iaskspider',
        'sogou web spider',
        'sogou push spider',
        'sosospider+',
        );

        $searchengine_name = array(
        'GOOGLE',
        'GOOGLE ADSENSE',
        'BAIDU',
        'MSN',
        'YODAO',
        'YAHOO',
        'Yahoo China',
        'IASK',
        'SOGOU',
        'SOGOU',
        'SOSO'
        );

        $spider = strtolower($_SERVER['HTTP_USER_AGENT']);

        foreach ($searchengine_bot AS $key => $value)
        {
            if (strpos($spider, $value)!== false){
                $spider = $searchengine_name[$key];
                return $spider;
            }
        }
        $spider = '';
        return '';
    }

    /**
	 * �ж��û���ϢCOOKIE���ܽ��ܷ��� UC_KEYΪi.cnmo.com��������� /www/cnmo/i_cnmo_new/config.inc.php
	 */
    public static function ucAuthCode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
        $ckey_length = 4;
        $key = md5($key ? $key : self::UC_KEY);
        $keya = md5(substr($key, 0, 16));
        $keyb = md5(substr($key, 16, 16));
        $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

        $cryptkey = $keya.md5($keya.$keyc);
        $key_length = strlen($cryptkey);

        $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
        $string_length = strlen($string);

        $result = '';
        $box = range(0, 255);

        $rndkey = array();
        for($i = 0; $i <= 255; $i++) {
            $rndkey[$i] = ord($cryptkey[$i % $key_length]);
        }

        for($j = $i = 0; $i < 256; $i++) {
            $j = ($j + $box[$i] + $rndkey[$i]) % 256;
            $tmp = $box[$i];
            $box[$i] = $box[$j];
            $box[$j] = $tmp;
        }

        for($a = $j = $i = 0; $i < $string_length; $i++) {
            $a = ($a + 1) % 256;
            $j = ($j + $box[$a]) % 256;
            $tmp = $box[$a];
            $box[$a] = $box[$j];
            $box[$j] = $tmp;
            $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
        }
        if($operation == 'DECODE') {
            if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
                return substr($result, 26);
            } else {
                return '';
            }
        } else {
            return $keyc.str_replace('=', '', base64_encode($result));
        }
    }


    /**
	 * ��Ʒ��� ��ҳ����
	 *
	 * @param array $param
	 * type���ͣ� 'param':
				 'dianping':
				 'price':
				 'pic':
				 'article':
				 'drive':
				 'video':
				 'tu':
				 'morepic':
				 'classpic':
	 */
    public static function getPaging(array $param)
    {
        $page = $param['page'];			#��ǰҳ	2
        $TotalPage = $param['totalPage'];	#��ҳ��	16
        $proId = $param['proId'];		#��Ʒid
        $type = empty($param['type']) ? '' : $param['type'];
        $picClassId = empty($param['picClassId']) ? 1 : $param['picClassId']; #ͼƬ�����
        if($page > $TotalPage) $page = $TotalPage;
        $strTemp = "";

        if($page>1){
            $index_page_url=Libs_Url::getProUrlByPage(array('proId' => $proId, 'page' => 1, 'type' => $type,'picClassId'=>$picClassId));
            $strTemp.='<a href="'.$index_page_url.'" class="last" target="_self">��ҳ</a>';
        }
        for ($i=1;$i<=$TotalPage;$i++){
            if ($i<$page-3) {
                if($i==0)$strTemp.='...';
                continue;
            }
            if ($i>$page+3) {
                $strTemp.='...';
                break;
            }
            if ($page==$i) {
                $strTemp.='<a class="cur">'.$i.'</a> ';
            }else{
                $cur_page_url = Libs_Url::getProUrlByPage(array('proId' => $proId, 'page' => $i, 'type' => $type,'picClassId'=>$picClassId));
                $strTemp.='<a class="page_num" href="'.$cur_page_url.'" target="_self">'.$i.'</a> ';

            }
        }
        if($page <$TotalPage){
            $next_page_url=Libs_Url::getProUrlByPage(array('proId' => $proId, 'page' => ($page+1), 'type' => $type,'picClassId'=>$picClassId));
            $last_page_url=Libs_Url::getProUrlByPage(array('proId' => $proId, 'page' => $TotalPage, 'type' => $type,'picClassId'=>$picClassId));
            $strTemp.='<a href="'.$next_page_url.'" class="anext" target="_self">��һҳ&nbsp;&gt;</a>';
            $strTemp.='<a href="'.$last_page_url.'" class="last" target="_self">βҳ&gt;&gt;</a>';
        }
        if($TotalPage==1){
            $strTemp='';
        }
        return $strTemp;
    }

    /**
	 * ��Ʒ���·�doctype ��ҳ����
	 *
	 * @param array $param
	 * doctype���ͣ�1������ 2������ 3������ 4������
	 */
    public static function getDoctypeArtPaging(array $param)
    {
        $page = $param['page'];			#��ǰҳ	2
        $TotalPage = $param['totalPage'];	#��ҳ��	16
        $proId = $param['proId'];		#��Ʒid
        $doctype = empty($param['doctype']) ? 1 : $param['doctype'];
        if($page > $TotalPage) $page = $TotalPage;
        $strTemp = "";

        if($page>1){
            $index_page_url=Libs_Url::getDocTypeProArticleUrl(array('proId' => $proId, 'page' => 1, 'doctype' => $doctype));
            $strTemp.='<a href="'.$index_page_url.'" class="last" target="_self">��ҳ</a>';
        }
        for ($i=1;$i<=$TotalPage;$i++){
            if ($i<$page-3) {
                if($i==0)$strTemp.='...';
                continue;
            }
            if ($i>$page+3) {
                $strTemp.='...';
                break;
            }
            if ($page==$i) {
                $strTemp.='<a class="cur">'.$i.'</a> ';
            }else{
                $cur_page_url = Libs_Url::getDocTypeProArticleUrl(array('proId' => $proId, 'page' => $i, 'doctype' => $doctype));
                $strTemp.='<a class="page_num" href="'.$cur_page_url.'" target="_self">'.$i.'</a> ';

            }
        }
        if($page <$TotalPage){
            $next_page_url=Libs_Url::getDocTypeProArticleUrl(array('proId' => $proId, 'page' => ($page+1), 'doctype' => $doctype));
            $last_page_url=Libs_Url::getDocTypeProArticleUrl(array('proId' => $proId, 'page' => $TotalPage, 'doctype' => $doctype));
            $strTemp.='<a href="'.$next_page_url.'" class="anext" target="_self">��һҳ&nbsp;&gt;</a>';
            $strTemp.='<a href="'.$last_page_url.'" class="last" target="_self">βҳ&gt;&gt;</a>';
        }
        if($TotalPage==1){
            $strTemp='';
        }
        return $strTemp;
    }

    /*
    js escape����  ��UTF8�� ��Ҫ����
    print iconv('utf-8', 'gb2312', js_unescape('%u8BFA%u57FA%u4E9A'));
    */
    public static function jsUnescape(array $param)
    {
        $str = $param['char'];
        $ret = '';
        $len = strlen($str);

        for ($i = 0; $i < $len; $i++)
        {
            if ($str[$i] == '%' && $str[$i+1] == 'u')
            {
                $val = hexdec(substr($str, $i+2, 4));

                if ($val < 0x7f) $ret .= chr($val);
                else if($val < 0x800) $ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f));
                else $ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f));

                $i += 5;
            }
            else if ($str[$i] == '%')
            {
                $ret .= urldecode(substr($str, $i, 3));
                $i += 2;
            }
            else $ret .= $str[$i];
        }
        return $ret;
    }
    /*header 404״̬*/
    public static function header_status($status)
    {
        // 'cgi', 'cgi-fcgi'
        if (substr(php_sapi_name(), 0, 3) == 'cgi')
        header('Status: '.$status, TRUE);
        else
        header($_SERVER['SERVER_PROTOCOL'].' '.$status);
    }


    const JS_PARAM_DELIMITER = '_';
    /**
	* ��ȡrewrite���Js·��
	* @param string $preStr ǰ׺ 
	* @param array $param ���� 
	* @param string $sufStr ��׺
	*/
    public static function getRewriteJsUrl($preStr, array $param = array(), $sufStr = 'html',$noRewite=false)
    {
        if (!$param) {
            return false;
        }
        $output->manuId =
        $manuId = !empty($param['manuId']) ? $param['manuId'] : 0;
        #������
        $param6 = $input->param6;
        $param['param6'] =
        $output->param6 =
        $param6 = !empty($param['param6']) ? $param['param6'] : 0;
        #��������
        $param1 = $input->param1;
        $param['param1'] =
        $output->param1 =
        $param1 = !empty($param['param1']) ? $param['param1'] : 0;
        #�۸�
        $paramprice = $input->paramprice;
        $param['paramprice'] =
        $output->paramprice =
        $paramprice = !empty($param['paramprice']) ? $param['paramprice'] : 0;
        #�ֻ�����
        $param103 = $input->param103;
        $param['param103'] =
        $output->param103 =
        $param103 = !empty($param['param103']) ? $param['param103'] : 0;

        $paramOS = $input->paramOS;
        $param['paramOS'] =
        $output->paramOS =
        $paramOS = !empty($param['paramOS']) ? $param['paramOS'] : 0;
        #query
        $param['query'] =
        $output->query =
        $query = !empty($param['query']) ? $param['query'] : 3;
        #var_dump($param);
        //$queryString = http_build_query($param);
        $queryString = implode(self::JS_PARAM_DELIMITER,$param);
        if(!$noRewite){
            //$queryString = str_replace('&', self::JS_PARAM_DELIMITER, $queryString);
            $url = $preStr . $queryString . '.' . $sufStr;
        }else{
            $url = "/index.php?c=Js&".$queryString;
        }
        return $url;
    }

    /**
    * ��������ҳ��ҳ
    * 
    * @param mixed $param
    */
    public static function getDownPaging(array $param)
    {
        $totalPage = !empty($param['totalPage']) ? $param['totalPage'] : 0;
        $currentPage = !empty($param['page']) ? $param['page'] : 0;
        $classId = !empty($param['classId']) ? $param['classId'] : 0;
        $subClassId = !empty($param['subClassId']) ? $param['subClassId'] : 0;
        $extend = !empty($param['extend']) ? $param['extend'] : 0;
        $picSize = !empty($param['picSize']) ? $param['picSize'] : 0;
        $platId = !empty($param['platId']) ? $param['platId'] : 0;
        $title = !empty($param['title']) ? $param['title'] : '';
        $firstPage = '';
        $prevPage = '';
        $nextPage = '';
        $lastPage = '';
        $pageStr = '';
        if(empty($totalPage) || empty($currentPage))
        {
            return false;
        }

        if($title){
            if($totalPage > 1)
            {
                $firstPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>1)).'" target="_self">��ҳ</a>';

            }
            if($currentPage > 1){
                $prevPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$currentPage-1)).'" target="_self">��һҳ</a>';
            }
            if($totalPage < 6){
                for($i=1;$i<=$totalPage;$i++){
                    if($currentPage == $i){
                        $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                    }else{
                        $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                    }
                }
            }else{
                if($currentPage-2 > 2){
                    $pageStr .= '...... ';
                    for($i=$currentPage-2;$i<=$currentPage;$i++){
                        if($currentPage == $i){
                            $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }else{
                            $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }
                    }
                }else{
                    for($i=1;$i<=$currentPage;$i++){
                        if($currentPage == $i){
                            $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }else{
                            $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }
                    }
                }
                if($currentPage+2 < $totalPage){
                    for($i=$currentPage+1;$i<=$currentPage+2;$i++){
                        if($currentPage == $i){
                            $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }else{
                            $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }
                    }
                    $pageStr .= '...... ';
                }else{
                    for($i=$currentPage+1;$i<=$totalPage;$i++){
                        if($currentPage == $i){
                            $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }else{
                            $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }
                    }
                }
            }
            if($totalPage > 1 && $currentPage+2 < $totalPage && $totalPage > 5){
                $allPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$totalPage)).'" target="_self">'.$totalPage.'</a>';
            }
            if($currentPage+1 <= $totalPage){
                $nextPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$currentPage+1)).'" target="_self">��һҳ&gt;</a>';
            }
            if($totalPage > 1){
                $lastPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"title"=>$title,"page"=>$totalPage)).'" target="_self">βҳ&gt;&gt;</a>';
            }
        }else{
            if($totalPage > 1)
            {
                $firstPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>1)).'" target="_self">��ҳ</a>';
            }
            if($currentPage > 1){
                $prevPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$currentPage-1)).'" target="_self">��һҳ</a>';
            }
            if($totalPage < 6){
                for($i=1;$i<=$totalPage;$i++){
                    if($currentPage == $i){
                        $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                    }else{
                        $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                    }
                }
            }else{
                if($currentPage-2 > 2){
                    $pageStr .= '...... ';
                    for($i=$currentPage-2;$i<=$currentPage;$i++){
                        if($currentPage == $i){
                            $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }else{
                            $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }
                    }
                }else{
                    for($i=1;$i<=$currentPage;$i++){
                        if($currentPage == $i){
                            $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }else{
                            $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }
                    }
                }
                if($currentPage+2 < $totalPage){
                    for($i=$currentPage+1;$i<=$currentPage+2;$i++){
                        if($currentPage == $i){
                            $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }else{
                            $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }
                    }
                    $pageStr .= '...... ';
                }else{
                    for($i=$currentPage+1;$i<=$totalPage;$i++){
                        if($currentPage == $i){
                            $pageStr .= '<a class="cur" href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }else{
                            $pageStr .= '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$i)).'" target="_self">'.$i.'</a>';
                        }
                    }
                }
            }
            if($totalPage > 1 && $currentPage+2 < $totalPage && $totalPage > 5){
                $allPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$totalPage)).'" target="_self">'.$totalPage.'</a>';
            }
            if($currentPage+1 <= $totalPage){
                $nextPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$currentPage+1)).'" target="_self">��һҳ&gt;</a>';
            }
            if($totalPage > 1){
                $lastPage = '<a href="'.Libs_Download_Url::getDownSearchUrl(array("classId"=>$classId,"subClassId"=>$subClassId,"extend"=>$extend,"picSize"=>$picSize,"platId"=>$platId,"page"=>$totalPage)).'" target="_self">βҳ&gt;&gt;</a>';
            }
        }

        return '<div class="page">'.$firstPage.$prevPage.$pageStr.$allPage.$nextPage.$lastPage.'</div>';
    }

    /**
    * ���ļ���С���е�λת��
    * 
    * @param mixed $size
    */
    public static function convertFileSize(array $param){
        $size = !empty($param['size'])? $param['size'] : 0;
        if($size>1024){
            return ((floor($size/1024*10))/10)."M";
        }else{
            return $size."KB";
        }
    }


    /*
    �ַ���ܽ��ܳ���
    */
    public static function zcms_encode($string, $operation = 'DECODE', $key = '', $expiry = 0) {

        $ckey_length = 4;
        $default_key = "KKShuahuaIODcvNv";

        $key = md5($key ? $key : $default_key);
        $keya = md5(substr($key, 0, 16));
        $keyb = md5(substr($key, 16, 16));
        $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

        $cryptkey = $keya.md5($keya.$keyc);
        $key_length = strlen($cryptkey);

        $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
        $string_length = strlen($string);

        $result = '';
        $box = range(0, 255);

        $rndkey = array();
        for($i = 0; $i <= 255; $i++) {
            $rndkey[$i] = ord($cryptkey[$i % $key_length]);
        }

        for($j = $i = 0; $i < 256; $i++) {
            $j = ($j + $box[$i] + $rndkey[$i]) % 256;
            $tmp = $box[$i];
            $box[$i] = $box[$j];
            $box[$j] = $tmp;
        }

        for($a = $j = $i = 0; $i < $string_length; $i++) {
            $a = ($a + 1) % 256;
            $j = ($j + $box[$a]) % 256;
            $tmp = $box[$a];
            $box[$a] = $box[$j];
            $box[$j] = $tmp;
            $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
        }

        if($operation == 'DECODE') {
            if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
                return substr($result, 26);
            } else {
                return '';
            }
        } else {
            return $keyc.str_replace('=', '', base64_encode($result));
        }
    }

    /**
    * ��ȡ������ip (squid �����»�����⣬������)
    * 
    */
    /*
    public static function get_client_ip()
    {
    if ($_SERVER['REMOTE_ADDR']) {
    $cip = $_SERVER['REMOTE_ADDR'];
    } elseif (getenv("REMOTE_ADDR")) {
    $cip = getenv("REMOTE_ADDR");
    } elseif (getenv("HTTP_CLIENT_IP")) {
    $cip = getenv("HTTP_CLIENT_IP");
    } else {
    $cip = "unknown";
    }
    return $cip;
    }*/


    /**
	 * ͨ��͸����������������ʵIP
	 *
	 * @return ip��ַ
	 */
    public static function get_client_ip()
    {
        $ip=false;
        if(!empty($_SERVER["HTTP_CLIENT_IP"])){
            $ip = $_SERVER["HTTP_CLIENT_IP"];
        }
        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
            if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
            for ($i = 0; $i < count($ips); $i++) {
                //echo $ips[$i].'<br>';
                if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) {
                    $ip = $ips[$i];
                    break;
                }
            }
        }
        return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
    }

    /**
	 * ��ʾǰ̨����ʾ��Ϣ��js��ʾ�����ر�ҳ
	 *
	 * @param  $str ��ʾ������
	 * @param  $back �Ƿ���ԭ����
	 */
    public static function showTips($str,$back=false){
        echo '<script type="text/javascript">alert("'.$str.'");';
        if($back){
            echo 'history.back(-1);';
        } else {
            echo 'window.location = location.href;';
        }
        echo'</script>';
    }

    /**
	 * �ݹ齨���ļ�Ŀ¼
	 * @param $filename �ļ�·��
	 * @param $mod Ȩ��ֵ Ĭ��Ϊ 0777
	 */
    public static function checkFilePathExist($filename,$mod='0777')
    {
        $str = substr($filename,0,strrpos($filename,'/'));
        $fa = explode('/',$str);
        $faPath = '';
        for ($i=0;$i<sizeof($fa);$i++){
            $faPath .= $fa[$i];
            if (!is_dir($faPath) && $fa[$i]){
                mkdir($faPath,$mod);
                chmod($faPath,$mod);
            }
            $faPath .= '/';
        }
    }

    /**
	 * д�ļ�����
	 *
	 * @param $content �ļ����� 
	 * @param $fileName �ļ�·��
	 * @param $writeType д�ļ���ʽ
	*/
    public static function writeFile($content,$fileName,$writeType='w+'){
        self::checkFilePathExist($fileName);
        $fp = fopen($fileName,$writeType);
        //    flock($fp, 2);
        fputs($fp, $content);
        //    flock($fp, 3);
        fclose($fp);
        @chmod($fileName,0777);
    }

    /**
	 * �õ�������֤��ͼƬ��������֤��Ϣд�뵽cookie��
	 * @param  $expired ʧЧʱ�� ��λ�� Ĭ��Ϊ3����
	 * �����Ƿ���ȷ��ʱ��ʹ�ã�
	 * $_COOKIE['valiCode'] ��֤������
	 *
	 */
    public static function getRandomValiCode($expired=180)
    {
        Header("Content-type:image/png");
        $expired = (int)$expired;
        if(!$expired){
            $expired = 180;
        }
        //����header������ͼƬ�ļ��������png���ް�Ȩ֮��;
        $authnum ="";
        //����Ҫ��ʾ�����֣��Դ�������µ���λ������֤��
        $str = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
        //����������ʾ��ͼƬ�ϵ����ֺ���ĸ;
        $l = strlen($str); //�õ��ִ��ĳ���;
        //ѭ������ȡ��λǰ�涨�����ĸ������;
        for($i=1;$i<5;$i++)
        {
            $num=rand(0,$l-1);
            //ÿ������ȡһλ����;�ӵ�һ���ֵ����ִ���󳤶�,
            //��1����Ϊ��ȡ�ַ��Ǵ�0��ʼ����;����34�ַ����ⶼ�п�����������;
            $authnum .= $str[$num];
            //��ͨ�����ֵ������ַ�������һ������λ;
        }
        //����λ���֣���ĸ����cookie�У����ΪvaliCode;
        setcookie ("valiCode",$authnum,time()+$expired);
        //�����֤��ͼƬ��
        srand((double)microtime()*1000000);
        $im = imagecreate(60,24);//ͼƬ�����;
        //��Ҫ�õ��ڰ׻�����ɫ;

        $black = ImageColorAllocate($im, 0,0,0);
        //$white = ImageColorAllocate($im, rand(0,255),rand(0,255),rand(0,255));
        $gray = ImageColorAllocate($im, rand(200,255),rand(100,255),rand(200,255));
        $white = ImageColorAllocate($im, 255,255,255);

        /*//�粻�ø����ߣ�ע�;�����;
        $li = ImageColorAllocate($im, 120,220,200);
        for($i=0;$i<3;$i++)
        {//����3��������;Ҳ���Բ�Ҫ;���������Ϊ����Ӱ���û�����;
        imageline($im,rand(0,40),rand(0,51),rand(20,60),rand(0,21),$li);
        } */
        //����λ������֤�����ͼƬ
        imagefill($im,68,30,$white);
        //�ַ���ͼƬ��λ��;
        imagestring($im, 5, 14, 3, $authnum, $white);
        for($i=0;$i<90;$i++)
        {//�����������
            imagesetpixel($im, rand()%70 , rand()%30 , $gray);
        }
        ImagePNG($im);
        ImageDestroy($im);
        exit;
    }


    /**
     * �����ַ�
     *
     * @param  $str
     * @return string
     */
    public function Xencode($str)
    {
        return $str;
    }


    /**
     * �����ַ�
     *
     * @param  $str
     * @return string
     */
    public function Xdecode($str)
    {
        return $str;
    }
    /**
     * �ж��Ƿ���֩��ץȡ
     *
     * @param  $str
     * @return string
     */
    public function IsOrNotSpider(){
        $spider_arr = array('spider','Googlebot','Yahoo ContentMatch Crawler','Yahoo! Slurp China','msnbot','YoudaoBot','CollapsarDSP');
        $spiderStatus=0;
        foreach ($spider_arr as $value)
        {
            if (ereg($value,$_SERVER['HTTP_USER_AGENT']))
            {
                $spiderStatus = 1;
            }
        }
        return $spiderStatus;
    }

    /**
     * *
     *
     * @param ���php����
     * @param  $array
     * @param  $file
     * @return 
     */
    public static function writeCache($arrayName,$array,$type=''){
        ob_start();
        var_export($array);
        $cache=ob_get_contents();
        ob_end_clean();
        if (!$type) {
            $cacheBegin = "<?php\r\n";
        }
        $cacheBegin .= "\${$arrayName}=";
        $cache= $cacheBegin.$cache.';';
        if (!$type) {
            $cache.="\r\n?>";
        }
        return $cache;
    }

    /**
     * ���÷�ҳ����
     * @param  $param
     * <pre>
     * page            ��ǰҳ����
     * pageSize        ÿҳ��¼��
     * total           ��¼����
     * baseUrl         ��url ���磺http://www.cnmo.com/aa_p
     * type            1 ��ҳ������ҳһ�� 2 ��ҳ�����ַ
     * indexUrl        �������ҳ��ַ,typeΪ2ʱ��Ҫ��Ϊ1ʱΪ��
     * fileExt         ҳ��ĺ�׺�� ��̬ʱΪ�ռ��ɣ���̬ʱ�� .html
     * @return  string          ��ҳ�ַ�
     * </pre>
     */
    public static function multiPage(array $param)
    {
        if(!$param || !$param['total']){
            return '';
        }
        //init
        $page = intval($param['page']); //��ǰҳ����
        $pageSize = intval($param['pageSize']); //��ǰҳ����
        $resultsSum = intval($param['total']); //�ܼ�¼��
        $baseUrl = trim($param['baseUrl']); //��url http://www.cnmo.com/aa
        $indexUrl = trim($param['indexUrl']); //��ҳurl������ҳ�����ҳ����ʾ
        $type = $param['type'] ? intval($param['type']) : 1; //��ҳ������,Ĭ��Ϊ��һ��
        $fileExt = trim($param['fileExt']); //url��׺��Ĭ��Ϊ��
        //�����ҳ��
        $pagesum = ceil($resultsSum/$pageSize);
        //���
        $pageStr = '';
        if(2 == $type){ //��ҳ�ر�ʱ
            //����1ҳʱ����һҳ������
            if ($page>1){
                if(1 == $page-1){
                    $pageStr.='<a target="_self" href="'.$indexUrl.'">&lt;��һҳ</a>';
                } else {
                    $pageStr.='<a target="_self" href="'.$baseUrl.($page-1).$fileExt.'">&lt;��һҳ</a>';
                }
            } else { //��һҳʱ����ʾһ����ɫ����һҳ��
                $pageStr.='<a target="_self" class="noprev">&lt;��һҳ</a>';
            }
            //�ȸ����ҳ����зֶδ���
            if($pagesum <=5){ //5ҳ����ʱ��ֱ��ȫ����ʾ
                for($i=1;$i<=$pagesum;$i++){
                    if($page == $i){
                        $pageStr.= '<span>'.$i.'</span>';
                    } else {
                        if(1 == $i){
                            $pageStr.= '<a target="_self" href="'.$indexUrl.'">1</a>';
                        } else {
                            $pageStr.= '<a target="_self" href="'.$baseUrl.$i.$fileExt.'">'.$i.'</a>';
                        }
                    }
                }
            } else if($pagesum>5){ //����5ҳʱ
                if($page<5){ //ǰ4ҳ���⴦�?ǰ�������ʾ3����������ʾһ������Ȼ��ʾβҳ������ʾ��ҳ
                    for($i=1;$i<=5;$i++){
                        if($page == $i){
                            $pageStr.= '<span>'.$i.'</span>';
                        } else {
                            if(1 == $i){
                                $pageStr.= '<a target="_self" href="'.$indexUrl.'">1</a>';
                            } else {
                                $pageStr.= '<a target="_self" href="'.$baseUrl.$i.$fileExt.'">'.$i.'</a>';
                            }
                        }
                    }
                    //�õ�βҳ
                    $pageStr.='...<a target="_self" href="'.$baseUrl.$pagesum.$fileExt.'">'.$pagesum.'</a>';

                } else if($page>=5  && $page<$pagesum-3){ //���ҳ��>=5 && <$pagesum-3 ʱ����ʾ����ͷ��β
                    //�õ���ҳ
                    $pageStr.='<a target="_self" href="'.$baseUrl.'1'.$fileExt.'">1</a>...';
                    $j = 0;
                    while($j<$pagesum){
                        $j++;
                        if($j<($page-2) && ($pagesum-$j)>4) continue;
                        elseif ($j>($page+2) && $j>5) break;
                        elseif ($j == $page) $pageStr.= '<span>'.$j.'</span>';
                        else {
                            if(1 == $j){
                                $pageStr.= '<a target="_self" href="'.$indexUrl.'">1</a>';
                            } else {
                                $pageStr.= '<a target="_self" href="'.$baseUrl.$j.$fileExt.'">'.$j.'</a>';
                            }
                        }
                    }
                    //�õ�βҳ
                    $pageStr.='...<a target="_self" href="'.$baseUrl.$pagesum.$fileExt.'">'.$pagesum.'</a>';
                } else { //��Ȼ����ʾβҳ�����������ʾ3����ǰ����ʾ1������ʾ��ҳ
                    //�õ���ҳ
                    $pageStr.='<a target="_self" href="'.$baseUrl.'1'.$fileExt.'">1</a>...';
                    for($i=$pagesum-4;$i<=$pagesum;$i++){
                        if($page == $i){
                            $pageStr.= '<span>'.$i.'</span>';
                        } else {
                            if(1 == $i){
                                $pageStr.= '<a target="_self" href="'.$indexUrl.'">1</a>';
                            } else {
                                $pageStr.= '<a target="_self" href="'.$baseUrl.$i.$fileExt.'">'.$i.'</a>';
                            }
                        }
                    }
                }
            }
            //��ҳ�����1�����һҳ֮ǰ��ʾ��һҳ
            if ($page<$pagesum && $pagesum>1) {
                $pageStr.='<a target="_self" href="'.$baseUrl.($page+1).$fileExt.'" class="prev">��һҳ&gt;</a>';
            }
            if($page == $pagesum){ //���һҳ����ʾ��ɫ����һҳ
                $pageStr.='<a target="_self" class="nonext">��һҳ&gt;</a>';
            }

        } else { //ȫ��һ��ʱ
            //����1ҳʱ����һҳ������
            if ($page>1){
                $pageStr.='<a target="_self" class="prev" href="'.$baseUrl.($page-1).$fileExt.'">&lt;��һҳ</a>';
            } else { //��һҳʱ����ʾһ����ɫ����һҳ��
                $pageStr.='<a target="_self" class="noprev">&lt;��һҳ</a>';
            }
            //�ȸ����ҳ����зֶδ���
            if($pagesum <=5){ //5ҳ����ʱ��ֱ��ȫ����ʾ
                for($i=1;$i<=$pagesum;$i++){
                    if($page == $i){
                        $pageStr.= '<span>'.$i.'</span>';
                    } else {
                        $pageStr.= '<a target="_self" href="'.$baseUrl.$i.$fileExt.'">'.$i.'</a>';
                    }
                }
            } else if($pagesum>5){ //����5ҳʱ
                if($page<5){ //ǰ4ҳ���⴦�?ǰ�������ʾ3����������ʾһ������Ȼ��ʾβҳ������ʾ��ҳ
                    for($i=1;$i<=5;$i++){
                        if($page == $i){
                            $pageStr.= '<span>'.$i.'</span>';
                        } else {
                            $pageStr.= '<a target="_self" href="'.$baseUrl.$i.$fileExt.'">'.$i.'</a>';
                        }
                    }
                    //�õ�βҳ
                    $pageStr.='...<a target="_self" href="'.$baseUrl.$pagesum.$fileExt.'">'.$pagesum.'</a>';

                } else if($page>=5  && $page<$pagesum-3){ //���ҳ��>=5 && <$pagesum-3 ʱ����ʾ����ͷ��β
                    //�õ���ҳ
                    $pageStr.='<a target="_self" href="'.$baseUrl.'1'.$fileExt.'">1</a>...';
                    $j = 0;
                    while($j<$pagesum){
                        $j++;
                        if($j<($page-2) && ($pagesum-$j)>4) continue;
                        elseif ($j>($page+2) && $j>5) break;
                        elseif ($j == $page) $pageStr.= '<span>'.$j.'</span>';
                        else {
                            $pageStr.= '<a target="_self" href="'.$baseUrl.$j.$fileExt.'">'.$j.'</a>';
                        }
                    }
                    //�õ�βҳ
                    $pageStr.='...<a target="_self" href="'.$baseUrl.$pagesum.$fileExt.'">'.$pagesum.'</a>';
                } else { //��Ȼ����ʾβҳ�����������ʾ3����ǰ����ʾ1������ʾ��ҳ
                    //�õ���ҳ
                    $pageStr.='<a target="_self" href="'.$baseUrl.'1'.$fileExt.'">1</a>...';
                    for($i=$pagesum-4;$i<=$pagesum;$i++){
                        if($page == $i){
                            $pageStr.= '<span>'.$i.'</span>';
                        } else {
                            $pageStr.= '<a target="_self" href="'.$baseUrl.$i.$fileExt.'">'.$i.'</a>';
                        }
                    }
                }
            }
            //��ҳ�����1�����һҳ֮ǰ��ʾ��һҳ
            if ($page<$pagesum && $pagesum>1) {
                $pageStr.='<a target="_self" href="'.$baseUrl.($page+1).$fileExt.'" class="prev">��һҳ&gt;</a>';
            }
            if($page == $pagesum){ //���һҳ����ʾ��ɫ����һҳ
                $pageStr.='<a target="_self" class="nonext">��һҳ&gt;</a>';
            }
        }
        return $pageStr;
    }

     /**
     * �򵥷�ҳ�ķ�ҳ������һҳ����һҳ������ť
     * @param  $param
     * <pre>
     * page            ��ǰҳ����
     * pageSize        ÿҳ��¼��
     * total           ��¼����
     * baseUrl         ��url ���磺http://www.cnmo.com/aa_p
     * type            1 ��ҳ������ҳһ�� 2 ��ҳ�����ַ
     * indexUrl        �������ҳ��ַ,typeΪ2ʱ��Ҫ��Ϊ1ʱΪ��
     * fileExt         ҳ��ĺ�׺�� ��̬ʱΪ�ռ��ɣ���̬ʱ�� .html
     * @return  string          ��ҳ�ַ�
     * </pre>
     */
    public static function simplePage(array $param)
    {
        if(!$param || !$param['total']){
            return '';
        }
        //init
        $page = intval($param['page']); //��ǰҳ����
        $pageSize = intval($param['pageSize']); //��ǰҳ����
        $resultsSum = intval($param['total']); //�ܼ�¼��
        $baseUrl = trim($param['baseUrl']); //��url http://www.cnmo.com/aa
        $indexUrl = trim($param['indexUrl']); //��ҳurl������ҳ�����ҳ����ʾ
        $type = $param['type'] ? intval($param['type']) : 1; //��ҳ������,Ĭ��Ϊ��һ��
        $fileExt = trim($param['fileExt']); //url��׺��Ĭ��Ϊ��
        //�����ҳ��
        $pagesum = ceil($resultsSum/$pageSize);
        //���
        $pageStr = '';
        //����
        $pageStr = $page.'/'.$pagesum;
        
        if(2 == $type){ //��ҳ��ͬʱ
            if($pagesum>1){ //����һҳʱ�ٿ���
                $pageStr .= '&nbsp;';
                if($page-1){ //��һҳ
                    if(1 == $page-1){
                        $pageStr.= '<a target="_self" href="'.$indexUrl.'">��һҳ</a>';
                    } else {
                        $pageStr.= '<a target="_self" href="'.$baseUrl.($page-1).$fileExt.'">��һҳ</a>';
                    }
                } else { //û����һҳ��
                    $pageStr.= '<a target="_self" class="prev">��һҳ</a>';
                }
                if($page+1>$pagesum){ //û����һҳ��
                    $pageStr.= '<a target="_self" class="end">��һҳ</a>';
                } else { //��һҳ
                    $pageStr.= '<a target="_self" class="next" href="'.$baseUrl.($page+1).$fileExt.'">��һҳ</a>';
                }
            }
        } else { //��ҳ��ͬʱ
            if($pagesum>1){ //����һҳʱ�ٿ���
                $pageStr .= '&nbsp;';
                if($page-1){ //��һҳ
                    $pageStr.= '<a target="_self" href="'.$baseUrl.($page-1).$fileExt.'">��һҳ</a>';
                } else { //û����һҳ��
                    $pageStr.= '<a target="_self" class="prev">��һҳ</a>';
                }
                if($page+1>$pagesum){ //û����һҳ��
                    $pageStr.= '<a target="_self" class="end">��һҳ</a>';
                } else { //��һҳ
                    $pageStr.= '<a target="_self" class="next" href="'.$baseUrl.($page+1).$fileExt.'">��һҳ</a>';
                }
            }
        }
        return $pageStr;
    }
}
